using System;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Text;
using System.Xml;

namespace Tool.BaseClass
{
	public class GClass39
	{
		public static bool smethod_0(string string_0, string string_1)
		{
			bool result = false;
			System.Net.HttpWebResponse httpWebResponse = null;
			System.Net.HttpWebRequest httpWebRequest = null;
			try
			{
				httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(string_0);
				httpWebRequest.Timeout = 30000;
				httpWebRequest.Method = "HEAD";
				httpWebRequest.CookieContainer = new System.Net.CookieContainer();
				httpWebRequest.Headers.Add("Accept-Language", "zh-CN");
				if (!string.IsNullOrEmpty(string_1))
				{
					httpWebRequest.UserAgent = string_1;
				}
				httpWebRequest.Accept = "*/*";
				GClass0.smethod_7(httpWebRequest, string_0);
				httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
				result = (httpWebResponse.StatusCode == System.Net.HttpStatusCode.OK);
			}
			catch
			{
				try
				{
					httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(string_0);
					httpWebRequest.Timeout = 30000;
					httpWebRequest.Method = "GET";
					httpWebRequest.CookieContainer = new System.Net.CookieContainer();
					httpWebRequest.Headers.Add("Accept-Language", "zh-CN");
					if (!string.IsNullOrEmpty(string_1))
					{
						httpWebRequest.UserAgent = string_1;
					}
					httpWebRequest.Accept = "*/*";
					GClass0.smethod_7(httpWebRequest, string_0);
					httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
					result = (httpWebResponse.ContentLength > 0L);
				}
				catch
				{
					result = false;
				}
			}
			finally
			{
				if (httpWebResponse != null)
				{
					httpWebResponse.Close();
				}
				if (httpWebRequest != null)
				{
					httpWebRequest.Abort();
				}
			}
			return result;
		}

		public static string smethod_1(string string_0, Encoding encoding_0, string string_1, string string_2 = null, System.Net.CookieContainer cookieContainer_0 = null)
		{
            if (string_0.EndsWith("101.171505.html?dwvar_101.171505_color=C6505&cgid=donna"))
            {
                return File.ReadAllText(@"d:\list.txt");
            }

            string result = "";
			System.Net.HttpWebRequest httpWebRequest = null;
			System.Net.HttpWebResponse httpWebResponse = null;
			try
			{
				string_0 = GClass0.smethod_5(string_0);
				httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(string_0);
				if (string.IsNullOrEmpty(string_2))
				{
					if (cookieContainer_0 == null)
					{
						httpWebRequest.CookieContainer = new System.Net.CookieContainer();
					}
					else
					{
						httpWebRequest.CookieContainer = cookieContainer_0;
					}
				}
				else
				{
					httpWebRequest.Headers.Set("cookie", string_2);
				}
				httpWebRequest.Timeout = 30000;
				httpWebRequest.ReadWriteTimeout = 30000;
				httpWebRequest.Method = "GET";
				httpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
				httpWebRequest.Headers.Add("Accept-Language", "zh-CN");
				if (!string.IsNullOrEmpty(string_1))
				{
					httpWebRequest.UserAgent = string_1;
				}
				httpWebRequest.Accept = "text/html, text/css";
				GClass0.smethod_7(httpWebRequest, string_0);
				httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
				if (!(httpWebResponse.ContentEncoding.ToLower() == "gzip"))
				{
					if (!(httpWebResponse.ContentEncoding.ToLower() == "deflate"))
					{
						using (Stream responseStream = httpWebResponse.GetResponseStream())
						{
							using (StreamReader streamReader = new StreamReader(responseStream, encoding_0))
							{
								result = streamReader.ReadToEnd();
							}
							goto IL_1F1;
						}
					}
					using (Stream responseStream = httpWebResponse.GetResponseStream())
					{
						using (System.IO.Compression.DeflateStream deflateStream = new System.IO.Compression.DeflateStream(responseStream, System.IO.Compression.CompressionMode.Decompress))
						{
							using (StreamReader streamReader = new StreamReader(deflateStream, encoding_0))
							{
								result = streamReader.ReadToEnd();
							}
						}
						goto IL_1F1;
					}
				}
				using (Stream responseStream = httpWebResponse.GetResponseStream())
				{
					using (System.IO.Compression.GZipStream gZipStream = new System.IO.Compression.GZipStream(responseStream, System.IO.Compression.CompressionMode.Decompress))
					{
						using (StreamReader streamReader = new StreamReader(gZipStream, encoding_0))
						{
							result = streamReader.ReadToEnd();
						}
					}
				}
				IL_1F1:;
			}
			catch (Exception ex)
			{
				result = ex.Message.ToString();
			}
			if (httpWebResponse != null)
			{
				httpWebResponse.Close();
			}
			if (httpWebRequest != null)
			{
				httpWebRequest.Abort();
			}
			return result;
		}

		public static string smethod_2(string string_0, string string_1)
		{
			ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
			byte[] bytes = aSCIIEncoding.GetBytes(string_1);
			System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(string_0);
			httpWebRequest.Timeout = 30000;
			httpWebRequest.ReadWriteTimeout = 30000;
			httpWebRequest.Method = "POST";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.ContentLength = (long)bytes.Length;
			Stream requestStream = httpWebRequest.GetRequestStream();
			requestStream.Write(bytes, 0, bytes.Length);
			requestStream.Close();
			System.Net.HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
			StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
			string result = streamReader.ReadToEnd();
			streamReader.Close();
			streamReader.Dispose();
			if (httpWebResponse != null)
			{
				httpWebResponse.Close();
			}
			if (httpWebRequest != null)
			{
				httpWebRequest.Abort();
			}
			return result;
		}

		public static string smethod_3(string string_0, XmlDocument xmlDocument_0)
		{
			System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(string_0);
			httpWebRequest.Timeout = 30000;
			httpWebRequest.ReadWriteTimeout = 30000;
			httpWebRequest.Method = "POST";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			Stream requestStream = httpWebRequest.GetRequestStream();
			xmlDocument_0.Save(requestStream);
			requestStream.Close();
			System.Net.HttpWebResponse httpWebResponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse();
			StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
			string result = streamReader.ReadToEnd();
			streamReader.Close();
			streamReader.Dispose();
			if (httpWebResponse != null)
			{
				httpWebResponse.Close();
			}
			if (httpWebRequest != null)
			{
				httpWebRequest.Abort();
			}
			return result;
		}
	}
}
